﻿using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class CodeNameRecord : WorkbookLevelRecord
    {
        private XLUnicodeString _value;

        public CodeNameRecord(string name)
        {
            _value = (XLUnicodeString) name;
        }

        public CodeNameRecord()
        {
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            _value.Read(context.Reader);
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.CodeName; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            _value.Write(context);
        }

        public override void Apply(BiffReaderWorkbookContext context)
        {
            context.Workbook.Name = (string) _value;
        }
    }
}